package com.example.controller.auth;

import com.example.common.result.Result;
import com.example.entity.auth.SysDept;
import com.example.service.auth.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : ssy
 * @date: 2024-03-27
 * @Description:
 */
@Api(tags = "部门管理接口")
@RestController
@RequestMapping("/api/system/sysDept")
public class SysDeptController {

    @Autowired
    private SysDeptService sysDeptService;

    @ApiOperation("获取所有部门")
    @GetMapping("findNodes")
    public Result<List<SysDept>> findNodes(){
        List<SysDept> list = sysDeptService.findNodes();
        return Result.success(list);
    }

    @ApiOperation("根据id获取部门")
    @GetMapping("findNodes/{id}")
    public Result<SysDept> getDeptById(@PathVariable Long id){
        SysDept dept = sysDeptService.getById(id);
        return Result.success(dept);
    }

    @ApiOperation(value = "新增部门")
    @PostMapping("save")
    public Result save(@RequestBody SysDept sysDept) {
        sysDeptService.save(sysDept);
        return Result.success();
    }

    @ApiOperation(value = "修改菜单")
    @PostMapping("update")
    public Result updateById(@RequestBody SysDept sysDept) {
        sysDeptService.updateById(sysDept);
        return Result.success();
    }

    @PreAuthorize("hasAuthority('bnt.sysDept.remove')")
    @ApiOperation(value = "删除菜单")
    @PostMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        sysDeptService.removeDeptById(id);
        return Result.success();
    }

    @ApiOperation(value = "更新状态")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        sysDeptService.updateStatus(id,status);
        return Result.success();
    }
}